package dynamicpojo.jackson;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;

import java.util.HashMap;
import java.util.Map;

//@NoArgsConstructor
//@AllArgsConstructor
//@SuperBuilder
//@Data
@ToString
public abstract class AbstractDynamicPojo {

    // 动态字段存储
    protected final Map<String, Object> dynamicProperties = new HashMap<>();

    // 设置和获取动态属性的方法
    public void put(String key, Object value) {
        System.out.println("Setting dynamic property: " + key + " -> " + value); // Debug log
        dynamicProperties.put(key, value);
    }

    public Object get(String key) {
        return dynamicProperties.get(key);
    }

    @JsonAnySetter
    public void setUnknownProperty(String name, Object value) {
        put(name, value);
    }

    @JsonAnyGetter
    public Map<String, Object> getUnknownProperties() {
        return dynamicProperties;
    }
}


